<?php
/**
 * 订单未支付提醒
 *
 * by abc.com 多用户商城
 *
 *
 */

//by abc.com
//use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');
class voucher_deadlineControl{
    
    public function __construct(){
        register_shutdown_function(array($this,"shutdown"));
    }
    /**
     * 代金券即将到期提醒
     * 每天执行两次
     * 
     */
    public function indexOp(){
        // 查找即将到期代金券
        $model_voucher = Model('voucher');
        $model_message_center = Model('message_center');
        $condition['voucher_end_date'] = array(array('lt', (TIMESTAMP + 259200)),array('gt',TIMESTAMP),'and'); 
        $voucher_list = $model_voucher->getVoucherList($condition);
        $model_member = Model('member');
        foreach ($voucher_list as $key => $val) {
            
            $member_info = $model_member->getMemberInfoByID($val['voucher_owner_id']);
            if ($member_info['member_truename'] != null && ! empty($member_info['member_truename'])) {
                $member_name = $member_info['member_truename'];
            } else {
                $member_name = substr_replace($member_info['member_mobile'], "****", 3, 4);
            }
            $msg['remark'] = $val['voucher_code'];
            $msg_info = $model_message_center->getOneMsg($msg);
            if ($msg_info == null || empty($msg_info)) {
                $time=date('Y-m-d H:i:s',$val['voucher_end_date']);
                $data['msg_content'] = "亲爱的" . $member_name . "，您的" . $val['voucher_title'] . "截止日期为" . $time . "，即将过期。可在我的优惠券页面查看。";
                $data['msg_type'] = 2;
                $data['msg_receive_id'] = $val['voucher_owner_id'];
                $data['msg_receive_name'] = $member_info['member_mobile'];
                $data['msg_time'] = TIMESTAMP;
                $data['msg_state'] = 1;
                $data['remark'] = $val['voucher_code'];
                $result = $model_message_center->saveMsg($data);
            }
        }
    }
    
    
  
}
    